import React from "react";
import main from "./main";
import PropTypes from "prop-types";
import QRCode from 'qrcode.react';
import styleMy from "../css/main.css";
import axios from "axios/index";

class ShowErwei extends React.Component {
    constructor(props, context) {
        super(props, context);
        this.GxToken = this.props.location.state.GxToken;
        this.schoolName =this.props.location.state.schoolName;
        this.sceneId =this.props.location.state.sceneId;
        this.wxTicket=this.props.location.state.wxTicket;
        this.wxUrl='https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=';
        this.state={
            appInstalledCount:'',
            weiXinFollowedCount:''
        }
    }
    componentWillMount () {
        axios.defaults.withCredentials = true;
        axios.get('http://guoxue.boyueguoxue.cn/Channel/getSchoolWxUserCount.do?schoolSceneId='+this.sceneId+'&browsGxToken='+this.GxToken  )
            .then(response => {
                let code=response.data.appInstalledCount;
                let message=response.data.weiXinFollowedCount;
                console.log(code);
                this.setState({
                    appInstalledCount:code,
                    weiXinFollowedCount:message
                })
                // if(code==200){
                //     let data=response.data.data;
                //     this.context.router.push(  {pathname:'/main/',state:{uid:data.uid,GxToken:data.GxToken,GxSID:data.GxSID}});
                //
                // }else {
                //     alert(message);
                //     return;
                // }
            })
            .catch(function (error) {
                alert(error)
            })
    }

    render(){

     return(
         <div className={styleMy["main-list"]}>
             <div className={styleMy["main-textCenter"]}>
             学校：{this.schoolName}
             <br/>
                 <br/>
                 已有{this.state.weiXinFollowedCount}人通过此二维码关注公众号
                 <br/>
                 已有{this.state.appInstalledCount}人通过二维码下载APP
                 <br/>
                 <br/>
                 <br/>
                 <a href={this.wxUrl+this.wxTicket}>点击获取公众号二维码
             </a>
                 <br/>
                 <br/>
                 <a href="javascript:void(0);" onClick={() => this.goAppErwei()}>点击获取APP二维码
                 </a>
             </div>

             <br/>
             <br/> <br/>

             <a href="javascript:void(0);" onClick={() => this.Showkefu()}>联系客服</a>

         </div>
     )
    }

    Showkefu() {
        alert("请拨打客服电话：02885283249，联系客服反馈问题。")
    }

    goAppErwei() {
        this.context.router.push(  {pathname:'/AppErwei/',state:{sceneId:this.sceneId}});

    }
}



ShowErwei.contextTypes = {
    router: PropTypes.object.isRequired
};

export default ShowErwei;